// pages/my/my.js
//获取应用实例
import {login} from "../../utils/asyncWx"
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    damon: false,
    userInfo:null,
    encryptedData:null,
    rawData:null,
    iv:null,
    signature:null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function  (options) {
    let userInfo = wx.getStorageInfoSync("userInfo")
    if(userInfo) {
      this.setData({
        userInfo: userInfo
      })
    }
    // 查看是否授权
    wx.getSetting({
      success: (res) => {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称
          wx.getUserInfo({
            success: (res) => {
              this.setData({ 
                damon: true,
                userInfo: res.userInfo
              })
              app.globalData.userInfo = res.userInfo
              console.log(app.globalData.userInfo,'app.globalData.userInfo');
            }
          })
        }
      }
    })
  },
  async bindGetUserInfo (e) {
    const {encryptedData, rawData,iv, signature} = e.detail
    const {code} = await login()
    console.log(encryptedData, rawData,iv, signature,'     ddddd   ',code);
    this.setData({
      userInfo: e.detail.userInfo
    })
    app.globalData.userInfo = e.detail.userInfo
    wx.setStorageSync('userInfo', this.data.userInfo)
  },
  getPhoneNumber(e) {
    console.log(e);
    
  },
  handleContact (e) {
    console.log(e.detail.path)
    console.log(e.detail.query)
  },
})